import os

def create_symbolic_link(source, target):
    try:
        # 检查目标目录是否存在，如果不存在则创建
        target_dir = os.path.dirname(target)
        if not os.path.exists(target_dir):
            os.makedirs(target_dir)

        # 创建符号链接
        os.symlink(source, target)
        print(f"Symbolic link '{target}' created for '{source}'.")
    except OSError as e:
        print(f"Failed to create symbolic link '{target}': {e}")

# 指定源文件和目标链接路径
source = "/home/pan/dotfiles/clash/clash.service"
target = "/home/pan/.config/systemd/user/clash.service"

# 调用函数创建符号链接
create_symbolic_link(source, target)
